import { createRouter, createWebHistory } from 'vue-router'


const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/:catchAll(.*)',
    name: '404',
    component: () => import('../views/404.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/home/Home.vue'),
    meta: {
      title: '网上商城'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('../views/profile/Profile.vue'),
    meta: {
      title: '个人中心'
    }
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/profile/Register.vue'),
    meta: {
      title: '账号注册'
    }
  },
  {
    path: '/detail',
    name: 'Detail',
    component: () => import('../views/detail/Detail'),
    meta: {
      title: '订单详情'
    }
  },
  {
    path: '/category',
    name: 'Category',
    component: () => import('../views/category/Category.vue'),
    meta: {
      title: '商品分类'
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/profile/Login.vue'),
    meta: {
      title: '用户登录'
    }
  },
  {
    path: '/shopcart',
    name: 'Showcart',
    component: () => import('../views/shopcart/Shopcart.vue'),
    meta: {
      title: '购物车'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  next()
  document.title = to.meta.title
}) 

 

export default router
